

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;


public class Bed {
    
     
    private String BedID;
    private int RoomID;
    private int BedStatus;

    /**
     *get BedID
     *@return BedID
     */
    public String getBedID() {
        return BedID;
    }

    /**
     *set id for field BedID
     */
    public void setBedID(String BedID) {
        this.BedID = BedID;
    }

    /**
     *get RoomID
     *@return RoomID
     */
    public int getRoomID() {
        return RoomID;
    }

    /**
     *set id for field RoomID
     */    
    public void setRoomID(int RoomID) {
        this.RoomID = RoomID;
    }

    /**
     *get BedStatus
     *@return BedStatus
     */
    public int getBedStatus() {
        return BedStatus;
    }

    /**
     *set status for BedStatus 
     */    
    public void setBedStatus(int BedStatus) {
        this.BedStatus = BedStatus;
    }

    /**
     *get all record in table Bed 
     *@return Vector v
     */
    public static Vector getAllBed() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllBeds");
            while(rs.next()){
                Bed b = new Bed();
                b.setRoomID(rs.getInt(1));
                b.setBedID(rs.getString(2));
                b.setBedStatus(rs.getInt(3));
                v.add(b);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   
    

    /**
     *get record in table Bed 
     *@return Vector v
     */
    public static Vector getBedByRoomId(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add((Integer)id);
            ResultSet rs = DBHelper.executeQuery("spSearchBedByID", paramList);
   
            while(rs.next()){
                Bed b = new Bed();
                b.setBedID(rs.getString(1));
                b.setRoomID(rs.getInt(2));
                b.setBedStatus(rs.getInt(3));
                v.add(b);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     

    public static Vector getBedByBedId(String id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(id);
            ResultSet rs = DBHelper.executeQuery("spSearchBedByBedID", paramList);
            
            while(rs.next()){
                Bed b = new Bed();
                b.setBedID(rs.getString(1));
                b.setRoomID(rs.getInt(2));
                b.setBedStatus(rs.getInt(3));
                v.add(b);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }   
    
        public static String getBedByPatientId(int id)
    {    
            String bedid="";
		 try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(id);
            ResultSet rs = DBHelper.executeQuery("getBedID", paramList);
            
            while(rs.next()){
                bedid=rs.getString(1);
            }
        } catch(SQLException sqle) {sqle.printStackTrace(); }   
        return bedid;
    }
        
    public static Vector getBedByName(String name) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);
            ResultSet rs = DBHelper.executeQuery("spSearchBedByName", paramList);           
            while(rs.next()){
                Bed b = new Bed();
                b.setBedID(rs.getString(1));
                b.setRoomID(rs.getInt(2));
                b.setBedStatus(rs.getInt(3));
                v.add(b);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }  
    

    public static int insertBed(Bed b) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(b.BedID);
            paramList.add(b.RoomID);
            paramList.add(b.BedStatus);
            i=DBHelper.executeUpdate("spInsertBed",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }
    public static int deleteBed(String id) throws SQLException
    {
        int i;
        try {        
            Vector paramList = new Vector();
            paramList.add(id);
            i = DBHelper.executeUpdate("spDeleteBedByID", paramList);          
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }               
        return i;
    }
    public static int updateBedStatus(String id, int stt) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(id);
            paramList.add((Integer)stt);
            i=DBHelper.executeUpdate("spUpdateBedByID",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }    
    
}
